package cn.itrip.auth.service;

import cn.itrip.common.RedisAPI;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Properties;

@Service(value = "mailService")
public class MailService{
    @Resource
    private MailSender mailSender;
    @Resource
    private RedisAPI redisAPI;
    @Resource
    private SimpleMailMessage simpleMailMessage;
    public void sendMail(String to,String code){
        simpleMailMessage.setFrom("1727952978@qq.com");
        simpleMailMessage.setTo(to);
        simpleMailMessage.setText("当前您正在进行爱旅行账号注册邮箱号为"+to+"激活码为:"+code);
        mailSender.send(simpleMailMessage);
        this.saveActivationInfo("activation"+to,code);

    }
    /**
     * 保存激活信息
     *
     * @param key
     * @param value
     */
    private void saveActivationInfo(String key, String value) {
        redisAPI.set(key, 30*60, value);
    }
}
